import { userStore } from "@/store/user";
import { Directive } from "vue";
//自定义按钮权限
export const permisson: Directive = {
    mounted(el, binding) {
        const store = userStore()
        //按钮上的权限字段
        const { value } = binding;
        //当前用户的所有权限字段
        const permisson = store.getCodeList
        if (value && value instanceof Array && value.length > 0) {
            const permissonRoles = value;
            //判断按钮权限是否存在用户的权限里面
            const hasPermisson = permisson.some((role) => {
                return permissonRoles.includes(role)
            })
            //如果没有按钮权限，隐藏按钮
            if (!hasPermisson) {
                el.style.display = 'none'
            }
        } else {
            throw new Error("按钮权限的传递方式v-permission=['sys:role:add']")
        }
    }

}